// home/02callMaster/callMaster.js
var MAP = require('../../js/map.js')
var co = require('../../js/common.js')
// var ws = require('../../js/websocket.js')
var app = getApp()
var that
Page({
   data: {
      // orderList: [],
   },

   onLoad: function (options) {
      that = this
      // var param = { creator_uid: app.aData.userInfo.unionid }
      // co.getSelfApi('order/Mg/getOrderList', param, function (res) {
      //    that.setData({ orderList: res.data })
      // })
   },

   toDetail: function (e) {
      var order = this.data.orderList[e.currentTarget.id]
      wx.navigateTo({
         url: '/home/04order/detail?order_id=' + order.order_id
      })
   },

   createOrder: function (e) {
      MAP.wxGetLocation(function (res) {
         var param = co.addValueForKey({}, e.detail.value)
         param.creator_uid = app.aData.userInfo.unionid
         if (res.latitude) {
            param = co.addValueForKey(param, res, ['latitude', 'longitude'])
         } else {
            param = co.addValueForKey(param, app.aData.userInfo, ['latitude', 'longitude'])
         }
         that.createOrder2(param)
      })
   },

   createOrder2: function (param) {
      MAP.getLocationName(param, function (address) {
         param.position = address
         param = co.addValueForKey(param, app.aData.p)
         co.getSelfApi('order/Mg/createOrder', param, function (res) {
            console.log('【创建的订单祥情】', res)
            wx.navigateTo({
               url: '/home/04order/detail?order_id=' + res.data.order_id
            })
            // res.data.type = 'notice'
            // var msg = JSON.stringify(res.data)
            // ws.sendSocketMsg(msg, function (res2) {
            //    console.log('【发送后收到回调】', res2)
               
            // })
         })
      })
   }
})